package com.xjgc.msibase.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.jeecg.common.api.vo.Result;
import com.xjgc.msibase.entity.MsiServerRecord;
import com.xjgc.msibase.entity.MsiServerRecordInfo;
import com.xjgc.msibase.service.IMsiRealRecordInfoService;
import com.xjgc.msibase.service.IMsiServerRecordService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 实时接口传输记录
 *
 * @author: 小逗号
 * @date: 2023-9-28
 * @description:
 * @since:
 */
@Api(tags = "实时传输记录")
@RestController
@RequestMapping("/msibase/msiServerRecord")
public class MsiServerRecordController {
    @Resource
    private IMsiServerRecordService msiRealRecordService;
    @Resource
    private IMsiRealRecordInfoService msiRealRecordInfoService;

    @CrossOrigin
    @ApiOperation("分页列表查询")
    @GetMapping("/pageList")
    public Result<?> pageList(
            MsiServerRecord queryAo,
            @RequestParam(name = "page", defaultValue = "1") Integer pageNo,
            @RequestParam(name = "rows", defaultValue = "10") Integer pageSize
    ) {

        IPage<MsiServerRecord> page = msiRealRecordService.pageList(new Page<>(pageNo, pageSize), queryAo);
        return Result.ok(page);
    }

    @CrossOrigin
    @ApiOperation("根据id查询")
    @GetMapping("/getById")
    public Result<?> getById(@RequestParam(name = "id") String id) {
        MsiServerRecord msiRealRecord = msiRealRecordService.getById(id);
        return Result.ok(msiRealRecord);
    }


    @CrossOrigin
    @ApiOperation("记录明细")
    @GetMapping("/getInfo")
    public Result<?> getInfo(@RequestParam(name = "recordId") String recordId,
                             @RequestParam(name = "page", defaultValue = "1") Integer pageNo,
                             @RequestParam(name = "rows", defaultValue = "10") Integer pageSize
    ) {
        IPage<MsiServerRecordInfo> page = msiRealRecordInfoService.page(new Page<MsiServerRecordInfo>(pageNo, pageSize), new QueryWrapper<MsiServerRecordInfo>().lambda()
                .eq(MsiServerRecordInfo::getRecordId, recordId)
                .orderByAsc(MsiServerRecordInfo::getNode)
        );

        return Result.ok(page);


    }

}
